<template>
  <div id="OutboundDetails">
    <v-detail :detailData="inputData.detailData" :inputConfig="inputConfig" :rules="rules" @pop="setData" ref="input">
    </v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "OutboundDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object,
    },
  },
  data() {
    return {
      rules: {
        strategykey: [{ required: true, trigger: "change" }],
        datecodedays: [{ validator: this.verify1, trigger: "blur" }],
        minimumwaveqty: [{ validator: this.minimumwaveqty, trigger: "blur" }],
        qclocout: [{ validator: this.Validate, trigger: "blur" }],
      },
      whseidflag: true,
    };
  },
  computed: {
    inputConfig() {
      return [
        [
          {
            type: "select",
            label: this.$t('config.allocaStrategy'),
            props: "newallocationstrategy",
            options: this.getOptions("queryNewallocationstrategyDropDown"),
            disabled: this.whseidflag,
          },
          {
            type: "select",
            label: this.$t('config.strategykey'),
            props: "strategykey",
            options: this.getOptions("queryAllocatestrategyDropDown"),
            disabled: this.whseidflag,
          },
          {
            type: "select",
            label: this.$t('config.boxGroup'),
            props: "cartongroup",
            options: this.getOptions("queryCartonizationDropDown"),
            disabled: this.whseidflag,
          },
          {
            type: "select",
            label: this.$t('outbound.rotation'),
            props: "defaultrotation",
            options: this.getOptions("querycodeLkup/ROTATION"),
            disabled: this.whseidflag,
          },
          {
            type: "select",
            label: this.$t('config.rotateby'),
            props: "rotateby",
            options: this.getOptions("querycodeLkup/SKUROTATE"),
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "select",
            label: this.$t('config.dapicksort'),
            props: "dapicksort",
            options: this.getOptions("querycodeLkup/DAPICKSORT"),
            disabled: this.whseidflag,
          },
          {
            type: "select",
            label: this.$t('config.rplnsort'),
            props: "rplnsort",
            options: this.getOptions("querycodeLkup/RPLNSORT"),
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t('config.datecodedays'),
            props: "datecodedays",
            disabled: this.whseidflag,
          },
          {
            type: "table",
            label: this.$t('config.qclocout'),
            props: "qclocout",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input",
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG"),
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown"),
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG"),
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCCATEGRY"),
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input",
              },
            ],
            url: "/queryLoc/",
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "checkbox",
            label: this.$t('outbound.flowthruitem'),
            props: "flowthruitem",
            disabled: this.whseidflag,
          },
          {
            type: "checkbox",
            label: this.$t('outbound.cartonizeft'),
            props: "cartonizeft",
            disabled: this.whseidflag,
          },
          {
            type: "checkbox",
            label: this.$t('outbound.groupfteach'),
            props: "groupfteach",
            disabled: this.whseidflag,
          },
          {
            type: "checkbox",
            label: this.$t('outbound.conveyable'),
            props: "conveyable",
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "select",
            label: this.$t('outbound.bulkcartongroup'),
            props: "bulkcartongroup",
            options: this.getOptions("queryCartonizationDropDown"),
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t('outbound.minimumwaveqty'),
            props: "minimumwaveqty",
            disabled: this.whseidflag,
          },
          {
            type: "checkbox",
            label: this.$t('outbound.allowconsolidation'),
            props: "allowconsolidation",
            disabled: this.whseidflag,
          },
          {
            type: "checkbox",
            label: this.$t('outbound.verifylot04lot05'),
            props: "verifylot04lot05",
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "input",
            label: this.$t('outbound.serialnumberstart'),
            props: "serialnumberstart",
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t('outbound.serialnumbernext'),
            props: "serialnumbernext",
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t('outbound.serialnumberend'),
            props: "serialnumberend",
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t('outbound.rtxrplimitqty'),
            props: "rtxrplimitqty",
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t('outbound.rtxrpminqty'),
            props: "rtxrpminqty",
            disabled: this.whseidflag,
          },
        ],
      ];
    },
  },
  methods: {
    verify1(rule, value, callback) {
      if (value === "") {
        callback(new Error());
      } else {
        var re = /^[0-9]*$/;
        let te = value;
        let flag = re.test(te);
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
            this.inputData.detailData[rule.field] = 999;
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
          this.inputData.detailData[rule.field] = 999;
          callback(new Error());
        }
      }
    },
    minimumwaveqty(rule, value, callback) {
      if (value === "") {
        callback(new Error());
      } else {
        var re = /^[0-9]*$/;
        let te = value;
        let flag = re.test(te);
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
            this.inputData.detailData[rule.field] = 0;
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
          this.inputData.detailData[rule.field] = 0;
          callback(new Error());
        }
      }
    },
    Validate(rule, value, callback) {
      if (value === "") {
        callback();
      } else {
        this.$api.get(`/queryLocByLocKey/${value}`).then((res) => {
          
            if (!res.bean) {
              this.$message.error(this.$t('msg.msg7'));
              this.inputData.detailData[rule.field] = "";
              callback(new Error());
            } else {
              callback();
            }
        }).catch(e => {
          callback(new Error());
        })
      }
    },
    setData(data, id, callback) {
      this.inputData.detailData.qclocout = data.loc;
      callback(false);
    },
  },
  mounted() {
    if (this.$store.state.wms.toUpperCase().includes("WMWHSE")) {
      //仓库级
      this.whseidflag = false;
    }
  },
  components: {
    "v-detail": detail,
  },
};
</script>

<style scoped>
</style>
